import request from "../utils/request";
export default {
    getLoginLogList(pageNum, pageSize) {
        const params = {
            pageNum,
            pageSize
        }
        return request.get('/loginLog', {
            params
        }, {
            method: "get"
        })
    },
    deleteLoginLog(id) {
        let params;
        if (typeof id === "string") {
            params = {
                id: [id]
            }
            console.log("ssss")
            return request.delete("/loginLog/" + id, {}, {
                method: "delete"
            })
        } else {
            params = {
                id
            }
            const idsString = Array.isArray(id) ? id.join(',') : id.toString();
            console.log("xxxxx")
            return request.delete("/loginLog/" + idsString, {}, {
                method: "delete"
            })
        }
    },
    getSpecieLoginLog(username, ip, status, time, pageNum, pageSize) {
        const params = {
            username,
            ip,
            status,
            // 安全访问 time 数组，未选择时间时自动过滤字段
            ...(time?.[0] && { startTime: time[0] }),  // 仅当 time[0] 存在时添加 startTime
            ...(time?.[1] && { endTime: time[1] }),     // 仅当 time[1] 存在时添加 endTime
            pageNum,
            pageSize
        }
        return request.get('/loginLog/searchSpecieLoginLog', {
            params
        }, {
            method: "get"
        })
    },
    deleteAllLoginLog() {
        return request.delete("/loginLog", {}, {
            method: "delete"
        })
    }
}